﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GraphCompiler.Core.SyntaxRepresentation;

namespace GraphCompiler.Core.Parsing
{
    public class Parser : ParserBase<SyntaxNode>
    {
        ITypedParser<DiagramNode> _diagramParser;

        public Parser(ITypedParser<DiagramNode> diagramParser)
        {
            AddChildParser(diagramParser);
            _diagramParser = diagramParser;
        }

        public override SyntaxNode ParseTypedNode(TokenCollection tokens)
        {
            _tokens = tokens;

            if (IsTokenListEmpty)
                return new SyntaxNode();

            return ParseDiagramNode();
        }

        private SyntaxNode ParseDiagramNode()
        {
            return _diagramParser.ParseTypedNode(_tokens);
        }

        public override bool IsApplicable(TokenCollection tokens)
        {
            return !tokens.IsEmpty;
        }
    }
}
